<template>
  <div class="PieChart chart" ref="el" style="width: 100%;height: 300px;"></div>
</template>

<script setup>
import { ref, nextTick, onMounted, onBeforeUnmount } from 'vue'
import * as echarts from 'echarts'
import "echarts/theme/bee-inspired" // echarts theme

const el = ref(null)

let chart = null

onMounted(() => {
  nextTick(() => initChart())
})

onBeforeUnmount(() => {
  if (!chart) return
  chart.dispose()
  chart = null
})

function initChart() {
  chart = echarts.init(el.value, 'bee-inspired')
  chart.setOption({
    tooltip: {
      trigger: 'item',
      formatter: '{a} <br/>{b} : {c} ({d}%)'
    },
    legend: {
      left: 'center',
      bottom: '10',
      data: ['Industries', 'Technology', 'Forex', 'Gold', 'Forecasts']
    },
    series: [
      {
        name: 'WEEKLY WRITE ARTICLES',
        type: 'pie',
        roseType: 'radius',
        radius: [15, 95],
        center: ['50%', '38%'],
        data: [
          { value: 420, name: 'Industries' },
          { value: 240, name: 'Technology' },
          { value: 149, name: 'Forex' },
          { value: 100, name: 'Gold' },
          { value: 59, name: 'Forecasts' }
        ],
        animationEasing: 'cubicInOut',
        animationDuration: 2600
      }
    ]
  })

}
</script>

<style>
</style>